<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">派工记录编号：</label>
                                    <div class="layui-input-inline">
                                        <input name="dispatchWorkNumber" class="layui-input" type="text" placeholder="请输入派工记录编号"
                                               autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">派工操作人：</label>
                                    <div class="layui-input-inline">
                                        <input name="creatorName" class="layui-input" type="text" placeholder="请输入派工操作人"
                                               autocomplete="off"/>
                                    </div>
                                </div>


                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">创建时间：</label>
                                    <div class="layui-input-inline">
                                        <input id="pTime" class="layui-input date-icon" type="text"
                                               placeholder="选择创建时间"
                                               autocomplete="off" readonly/>
                                        <input name="startTime" id="startTime" style="display: none"/>
                                        <input name="endTime" id="endTime" style="display: none"/>
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">状态：</label>
                                    <div class="layui-input-inline">
                                        <input name="dispatchWorkStatus" id="dispatchWorkStatus" class="layui-input" type="text" placeholder="请输入状态"
                                               autocomplete="off"/>
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog"
                                            lay-submit layui-form-keyDownSearch="true">查询
                                    </button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置
                                    </button>
                                </div>


                            </div>
                        </div>
                    </div>
                </div>
                <div class="lay-btn-rows">
                    <div class="lay-btn-box">
                        <div class="lay-btn-lt">
                            <button id="dispatchWorkInfoBtnAdd" class="layui-btn icon-btn color-reseda">添加</button>
                        </div>
                        <div class="lay-btn-rt">
                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="workStationTable" lay-filter="workStationTable"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="workStationTableBar">
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="seeAttendanceDetail">详情</a>
            <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="editDispatchWork">编辑</a>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'laydate', 'admin', 'laytpl', 'tableTreeDj', 'config'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var laydate = layui.laydate;

        //时间范围
        laydate.render({
            elem: '#pTime',
            type: 'date',
            range: true,
            done: function (value, date, endDate) {
                if (value) {
                    var dateValue = value.split(" - ");
                    $("input[name='startTime']").val(dateValue[0] + " 00:00:00");
                    $("input[name='endTime']").val(dateValue[1] + " 23:59:59");
                } else {
                    $("input[name='startTime']").val("");
                    $("input[name='endTime']").val("");
                }
            }
        });

        // 渲染表格
        var insTb = table.render({
            elem: '#workStationTable',
            url: config.base + 'enterprise/product/admin/productDispatchWork/list',
            page: true,
            toolbar: true,
            defaultToolbar: ["filter"],
            cellMinWidth: 100,
            cols: [[
                  {type: 'numbers', title: '序号'}
                , {field: 'dispatchWorkNumber', sort: false, title: '派工记录编号'}
                , {field: 'deviceWorkshopName', sort: false, title: '所属车间'}
                , {field: 'attendanceGroupName', sort: false, title: '所属考勤组'}
                , {field: 'banCount', sort: false, title: '班次数', templet: function(d){
                        if(d.banCount!=undefined || d.banCount!=null || d.banCount!=''){
                            return d.banCount + '班次';
                        }else{
                            return "";
                        }
                  }}
                , {field: 'dispatchWorkCount', sort: false, title: '派工工位数'}
                , {field: 'dispatchWorkDate', sort: false, title: '派工日期'}
                , {field: 'dispatchWorkStatus', sort: false, title: '派工状态'}
                , {field: 'creatorName', sort: false, title: '添加人'}
                , {field: 'createTime', sort: false, title: '添加时间'}
                , {align: 'center', toolbar: '#workStationTableBar', title: '操作', width: 200}
             ]]
        });


        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });

        // 重置搜索
        form.on('submit(resets)', data => {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            let field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            insTb.reload({where: field, page: {curr: 1}}, 'data');
        });

        //监听排序
        table.on('sort(workStationTable)', function (obj) {
            table.reload('workStationTable', {
                initSort: obj
                , where: {
                    sort: obj.field
                    , order: obj.type
                }
            });
        });

        // 添加按钮点击事件
        $('#dispatchWorkInfoBtnAdd').click(function () {
            saveProductDispatchWorkInfo();
        });

        // 添加派工记录
        function saveProductDispatchWorkInfo() {
            let title = "添加派工记录";
            admin.formOpen({
                type: 1,
                area: ['78%', '84%'],
                style: 'font-size: 20px;',
                title: title,
                path: 'components/product/productDispatchWork/productSaveDispatchWorkInfo.html',
                end: function (data) {
                    insTb.reload({page: {curr: 1}}, 'data');
                }
            });
        }



        // 工具条点击事件
        table.on('tool(workStationTable)', function (obj) {
            let data = obj.data;
            if (obj.event === 'seeAttendanceDetail') {  //详情
                seeDetailDispatchWorkInfo(data);
            }else if(obj.event=='editDispatchWork'){ //编辑
                editProductDispatchWorkInfo(data);
            }
        });



        // 修改派工记录
        function editProductDispatchWorkInfo(data) {
            admin.putTempData("dispatchWorkInfoData",data);
            let title = "编辑派工记录";
            admin.formOpen({
                type: 1,
                area: ['78%', '84%'],
                style: 'font-size: 20px;',
                title: title,
                path: 'components/product/productDispatchWork/productEditDispatchWorkInfo.html',
                end: function () {
                    insTb.reload({page: {curr: 1}}, 'data');
                }
            });
        }

        function seeDetailDispatchWorkInfo(data) {
            admin.putTempData("dispatchWorkInfoData",data);
            let title = "派工记录详情";
            admin.formOpen({
                type: 1,
                area: ['78%', '84%'],
                style: 'font-size: 20px;',
                title: title,
                path: 'components/product/productDispatchWork/productDispatchWorkDetailInfo.html',
                end: function () {
                    insTb.reload({page: {curr: 1}}, 'data');
                }
            });
        }




    });
</script>